package com.xuruzi.demo.util.response;

import com.xuruzi.demo.util.BaseMsg;
import com.xuruzi.demo.util.MessageBuilder;

/**
 * Created by xuruzi on 2020/3/28.
 */
public class TextMsg extends BaseMsg {
    private StringBuilder contentBuilder;
    private String msgId;

    public TextMsg() {
        this.contentBuilder = new StringBuilder();
    }

    public TextMsg(String content) {
        this.setContent(content);
    }

    public String getContent() {
        return this.contentBuilder.toString();
    }

    public void setContent(String content) {
        this.contentBuilder = new StringBuilder(content);
    }

    public TextMsg add(String text) {
        this.contentBuilder.append(text);
        return this;
    }

    public TextMsg addln() {
        return this.add("\n");
    }

    public TextMsg addln(String text) {
        this.contentBuilder.append(text);
        return this.addln();
    }

    public TextMsg addLink(String text, String url) {
        this.contentBuilder.append("<a href=\"").append(url).append("\">").append(text).append("</a>");
        return this;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public String toXml() {
        MessageBuilder mb = new MessageBuilder(super.toXml());
        mb.addData("Content", this.contentBuilder.toString().trim());
        mb.addData("MsgId", this.msgId);
        mb.surroundWith("xml");
        return mb.toString();
    }
}
